home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************/
- /* Generic DRVR Installer */
- /* Written by Shane D. Looker, Glamourware Software */
- /* With special bug fixes by Paul Campbell, SuperMac Technologies */
- /* Based upon a strategy supplied by David Shayer, Apple Computer */
- /* */
- /* You need to add the ShowIcon code on your own. */
- /* */
- /* If you want real comments, add them! */
- /********************************************************************/
-
- #define NIL 0L
- #define NODRIVERERROR 131
-
- /*************************************************************************/
- /* Define the name of the DRVR resource you want to load. It must be a */
- /* Pascal string which has the period to indicate that it is a driver. */
- /*************************************************************************/
- #define INIT "\P.Ringworm"
-
- #define CalcResID(refNum, theID) (-16384 + (32 * refNum) + theID)
-
-
- /* This is the structure for the extended launch parameters */
- main()
- {
- short err;
- short drRef, slotNum;
- long oldA4;
-
- /* THINK C sets up A4 for your globals (I believe.) Just uncomment this */
- /* don't complain that I didn't use a #ifdef... */
- /* asm {
- move.l A4, oldA4
- move.l A0, A4
- }
- */
- if (!isoptionkey())
- {
-
-
- SetResLoad(TRUE);
-
- slotNum = Find_Slot();
- if (slotNum != 0)
- {
- drRef = Install_Driver(slotNum);
-
- if (drRef == 0)
- {
- return;
- }
- }
- }
-
-
- /* To fix A4 again if not in THINK C */
- /* asm {
- move.l oldA4, A4
- }
- */
- } /* End of MAIN program */
-
-
-
-
-
- short Install_Driver(slot)
- short slot;
- {
-
- Handle Drvr, Data;
- DCtlHandle *Hands;
- short r;
- short oldDataID, newDataID;
- char name[255];
- short theID, oldID, newID;
- ResType TheType, oldType;
- short err, rnum;
- short theResAttrs;
-
-
-
- Drvr = Get1NamedResource('DRVR', INIT);
-
- GetResInfo(Drvr, &oldID, &oldType, &name[0]);
- SetResInfo(Drvr, slot, &name[0]);
-
- oldID = CalcResID(oldID, 0);
- newID = CalcResID(slot, 0);
- Data = Get1Resource('DATA', oldID);
- SetResInfo(Data, newID, NIL);
-
- err = OpenDriver(INIT, &rnum);
-
- /****************************************************************************/
- /* The following two lines of code are commented out right now, but you can */
- /* re-install them to prevent the resources from being re-numbered */
- /****************************************************************************/
- /*
- theResAttrs = GetResFileAttrs(CurResFile());
- SetResFileAttrs(CurResFile(), theResAttrs && ~mapChanged);
- */
- UpdateResFile(CurResFile());
-
- HLock(Drvr);
- HLock(Data);
- HNoPurge(Drvr);
- HNoPurge(Data);
-
- DetachResource(Drvr);
- DetachResource(Data);
-
- /* You could issue an Control statement at this point if you wanted to */
- /*
- err = Control(rnum, accRun, NIL);
-
- if (err != 0)
- return(0);
- */
-
- return(rnum);
- }
-
-
- short Find_Slot()
- {
- DCtlHandle Hands = (DCtlHandle) -1;
- short slot;
-
-
- /* Paul Campbell says, "Don't go below Hex 28 (I Think.)" */
- for(slot = UnitNtryCnt-1; (slot > (short)0x28) && (Hands != NIL); slot--)
- Hands = GetDCtlEntry(-(slot-1));
-
- if (slot == (short) 0x28) /* OOPS! We Didn't Find An Open Slot! */
- slot = 0; /* you should really extend the unit table here ....*/
- /* newptr a new one, zero it, blockmove the old one, */
- /* to the new one, update UnitNtryCnt and UTableBase */
- /* But remember to turn off all interrupts first */
- /* We should now have an empty slot number or 0 */
-
- return(slot);
- }
-
-
- isoptionkey()
- {
- return(iskeydown(58));
- };
-
-
- /* What is THIS! Looks like an Intel map...
- The map looks like :
-
- 87654321 FEDCBA9
- for each byte.... HUMMMPH */
-
-
- iskeydown(keycode)
- int keycode;
- {
- /* returns true if the key specified in the map by
- keycode is down false otherwise */
-
- KeyMap thekeys;
- long mask;
- int bank;
- int temp;
-
- GetKeys(&thekeys); /* check what keys are down -- Option is 58 */
-
- bank = keycode / 32; /* get the right bank to use */
- temp = (keycode % 32); /* ok now get the byte .... */
-
- temp = ((temp / 8 ) * 8 ) + ( 7 - (temp % 8));
-
- mask = 1L << ( 31 - temp);
- if (( thekeys.Key[bank] & mask ) == 0 )
- return(0);
- else
- return(1);
- };
-
-